package com.nwcl.basic.service.impl;

import com.nwcl.basic.bo.CouponsReceiveBO;
import com.nwcl.basic.dao.CouponsReceiveDao;
import com.nwcl.basic.entity.CouponsReceive;
import com.nwcl.basic.service.CouponsReceiveService;
import com.nwcl.common.utils.BeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.Collections;
import java.util.Date;
import java.util.List;

/**
 * @author liguiqin
 * @date 2023/5/30
 */
@Service
public class CouponsReceiveServiceImpl implements CouponsReceiveService {
    @Autowired
    private CouponsReceiveDao couponsReceiveDao;

    @Override
    public List<CouponsReceiveBO> listByUserIdAndTime(Integer userId, Date time) {
        List<CouponsReceive> list =  couponsReceiveDao.listByUserIdAndTime(userId, time);
        if(CollectionUtils.isEmpty(list)){
            return Collections.emptyList();
        }
        return BeanUtil.copyList(list, CouponsReceiveBO.class);
    }

    @Override
    public Integer save(CouponsReceiveBO receiveBO) {
        CouponsReceive receive = BeanUtil.copy(receiveBO, CouponsReceive.class);
        couponsReceiveDao.save(receive);
        return receive.getId();
    }

    @Override
    public CouponsReceiveBO getById(Integer id) {
        CouponsReceive receive = couponsReceiveDao.getById(id);
        if(null != receive){
            return BeanUtil.copy(receive, CouponsReceiveBO.class);
        }
        return null;
    }

    @Override
    public void updateStatus(Integer id, Integer status) {
        couponsReceiveDao.updateStatus(id,status);
    }
}
